Particle Set
Simulate trajectories of a particle cloud in a two-dimensional flow field. A doubly-periodic domain and randomly-generated flow fields are initially used. For additional documentation e.g. see : 1, 2, 3, 4
Exercises:
- change the initial distribution of partices
- increase the duration of the trajectories simulation
- treat the non-periodic domain case by padding
u,vwith zeros - replace
u,vwith your own two-dimensional flow fields

1. Import Software
using IndividualDisplacements, DataFrames
p=dirname(pathof(IndividualDisplacements))
include(joinpath(p,"../examples/flow_fields.jl"));2. Flow Fields
A convenient way to set up the flow fields using the MeshArrays.jl package (which handles such staggered grids in general fashion) is to call the convert_to_FlowFields function with u,v arrays and time span as arguments.
u,v,ฯ=random_flow_field()
๐น=convert_to_FlowFields(u,v,10.0);In the above, the u,v arrays generated by random_flow_field can be replaced with any other pair provided by the user.
A couple of important considerations, however:
u,vare staggered on a C-grid; by-0.5grid point in direction1foru(2forv)
from the grid cell center (0.5,0.5)
u,vhere derive from streamfunctionฯ, defined at the corner point, which ensures that
the resulting u,v is non-divergent, purely rotational, over the C-grid domain. In brief:
u=-(circshift(ฯ, (0,-1))-ฯ)
v=(circshift(ฯ, (-1,0))-ฯ)If user were to start with collocated velocity (uC,vC at the grid cell center) then one can easily obtain the staggered velocity (u,v) as follows. These may contain both rotational and divergent components.
u=0.5*(circshift(uC, (0,1))+uC)
v=0.5*(circshift(vC, (1,0))+vC)3. Initialize Individuals
For example, we can initialize 100 particles within a central subdomain as follows.
np,nq=size(u)
x=np*(0. .+ 1.0*rand(1000))
y=nq*(0. .+ 1.0*rand(1000))
a=ones(size(x)); #subdomain array index (just 1 here)The following constructor function wraps everything in the Individuals data structure.
๐ผ=Individuals(๐น,x,y,a) ๐ details = (1, 1000) Array{Float64,1}
๐ด details = (0, 5) ["ID", "x", "y", "fid", "t"]
๐ range = (1, 1000)
๐ function = dxy_dt!
โซ function = default_solver
๐ง function = postprocess_MeshArray
๐ details = (:u0, :u1, :v0, :v1, :๐, :update_location!)
3. Compute Trajectories
The time period is ๐ผ.๐.๐ by default, unless โซ!(๐ผ,๐) is called instead.
โซ!(๐ผ)1ร1000 Array{Array{Float64,1},2}:
[9.25755, 8.49568, 1.0] โฆ [0.229211, 12.9686, 1.0]4. Plot Results
For example, generate a simple animation:
p=dirname(pathof(IndividualDisplacements))
include(joinpath(p,"../examples/recipes_plots.jl"));
๐ด_by_t = groupby(๐ผ.๐ด, :t)
anim = @animate for t in eachindex(๐ด_by_t)
phi_scatter(ฯ,๐ด_by_t[t])
end
pth=tempdir()*"/"
gif(anim, pth*"RandomFlow.gif", fps = 10)This page was generated using Literate.jl.